<template>
  <div class="update">
    <Form :shopInfo="shopInfo" :data-list="dataList"/>
  </div>
</template>

<script lang="ts">
import {Component, Vue} from "vue-property-decorator";
import Form from "@/views/meal/Update/Form.vue";
import {getShopInfo} from "@/api/businessCenter/setting";
import {getMealList} from "@/api/meal/meal";

@Component({
  components: {
    Form,
  },
})
export default class Index extends Vue {
  // 套餐列表
  dataList = [];

  // 店铺信息
  shopInfo: any = {};

  created() {
    this.getDataList();
    this.getInfo();
  }

  /**
   * 获取套餐列表
   */
  async getDataList() {
    try {
      const response = await getMealList(this.shopInfo.tenantId);
      const {code, data} = response.data;
      if (code === 200) {
        this.dataList = data;
        this.dataList.forEach(meal => {
          if (meal.functionDesc && typeof meal.functionDesc === "string") {
            meal.functionDesc = meal.functionDesc.split(",");
          }
          if (meal.discountsJson && typeof meal.discountsJson === "string") {
            meal.discountsJson = JSON.parse(meal.discountsJson);
          }
        });
      } else {
        this.$message({
          type: "warning",
          message: "获取套餐信息失败！",
        });
      }
    } catch (err) {
      console.log(err);
    }
  }

  getInfo() {
    if (this.$route.query.shopInfo && typeof this.$route.query.shopInfo === "string") {
      this.shopInfo = JSON.parse(this.$route.query.shopInfo);
      this.getDataList();
      console.log(this.shopInfo);
    }
  }
}
</script>

<style lang="scss" scoped>
.update {
  padding: 15px;
  color: #515a6e;
  font-size: 13px;
  background-color: #ffffff;
}
</style>
